const path = require('path');
const HTMLWebpackPlugin = require('html-webpack-plugin');
const {
  CleanWebpackPlugin
} = require('clean-webpack-plugin');
const config = {
  // 指定打包的入口文件
  entry: './src/index.ts',
  // 此处无需配置mode的类型，在命令行中配置
  // 指定打包文件所在的目录
  output: {
    // 指定打包文件的目录
    path: path.resolve(__dirname, 'dist'),
    // 打包后文件的名称
    filename: 'bundle.js'
  },

  // 打包webpack打包时要使用的模块
  module: {
    // 指定加载的规则
    rules: [{
        test: /\.css$/,
        use: 'css-loader'
      },
      {
        test: /\.less$/i,
        use: [
          // compiles Less to CSS
          "style-loader",
          "css-loader",
          "less-loader",
        ],
      },
      {
        test: /\.ts$/,
        use: 'ts-loader'
      }
    ]
  },
  plugins: [
    new HTMLWebpackPlugin({
      title: '标题',
      template: './src/index.html'
    }),
    new CleanWebpackPlugin()
  ],

  resolve: {
    extensions: ['.ts', '.js']
  }
}

module.exports = config;